package com.leil.fileserver.config;

import com.leil.fileserver.client.MinIOClient;
import com.leil.fileserver.exception.FileOptException;
import com.leil.fileserver.properties.MinIOProperties;
import com.leil.fileserver.properties.UploadProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@EnableConfigurationProperties({UploadProperties.class})
public class MinIOConfig {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MinIOProperties minIOProperties;


    @Bean
    public MinIOClient minIOClient() {
        MinIOClient minIOClient = null;
        try {
            minIOClient = new MinIOClient(
                    minIOProperties.getEndpoint(),
                    minIOProperties.getAccessKey(),
                    minIOProperties.getSecretKey()
            );
        } catch (FileOptException e) {
            logger.error(e.getMessage());
        }
        return minIOClient;
    }



}
